package com.qfedu.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qfedu.bean.AtkSkill;
import com.qfedu.bean.ControlSkill;
import com.qfedu.bean.PageVo;
import com.qfedu.bean.result.QueryResult;
import com.qfedu.bean.result.ResultEnum;
import com.qfedu.dao.IAtkSkillDao;
import com.qfedu.dao.IControlSkillDao;
import com.qfedu.service.IAtkSkillService;
import com.qfedu.service.IControlSkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author WHW
 * @Description
 * @Date 2022/6/15
 */
@Service
public class ControlSkillServiceImpl implements IControlSkillService {

    @Autowired
    private IControlSkillDao controlSkillDao;


    @Override
    public QueryResult<ControlSkill> selectByPage(PageVo vo) {
        if(vo!=null && !StringUtils.isEmpty(vo.getName())) {
            vo.setName("%"+vo.getName()+"%");
        }


        PageHelper.startPage(vo.getPage(),vo.getLimit());
        Page<ControlSkill> page = (Page<ControlSkill>) controlSkillDao.selectByPage(vo);

        QueryResult<ControlSkill> qr = new QueryResult<>(ResultEnum.SELECT_SUCCESS);
        qr.setCount((int)page.getTotal());
        qr.setPages(page.getPages());
        qr.setData(page.getResult());

        return qr;
    }

    @Override
    public int add(ControlSkill controlSkill) {
        return controlSkillDao.add(controlSkill);
    }

    @Override
    public int deleteById(Integer id) {
        return controlSkillDao.deleteById(id);
    }

    @Override
    public int updateById(ControlSkill controlSkill) {
        return controlSkillDao.updateById(controlSkill);
    }
}
